Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a loading functionality to eliminate race condition in ResetFreeBankAccount #12112

Closed
wants to merge 2 commits into from

Conversation

ctkochan22
Copy link
Contributor

@Expensify/pullerbear @MariaHCD @nkuoch

Details

When adding a VBBA, and you click "Start Over". There is a race between:

  1. ResetFreeBankAccount
  2. Fetching the VBBA associated with the free plan when opening ReimbursementAccountPage.js

Sometimes ResetFreeBankAccount will not finish before we open the ReimbursementAccountPage, which means we still show the last step of the previous flow, despite the setup VBBA was reset

Fixed Issues

$ https://github.com/Expensify/Expensify/issues/238317

Tests / QA

  1. Create a workspace
  2. Go to workspace settings -> Connect Bank Account
  3. Use plaid and use user_good and pass_good. Get past the CompanyStep, whatever you need to do to get to Personal Information (RequestorStep)
  4. Now exit the flow
  5. Go back to workspace settings -> Connect Bank Account
  6. You will be presented with the option to continue the setup, or "Start Over".
    image
  7. Click Start Over
  8. Verify that you see a spinner, and that you are then directed to the original first step which makes you choose between Plaid and Manual
    image

PR Review Checklist

PR Author Checklist

  • I linked the correct issue in the ### Fixed Issues section above
  • I wrote clear testing steps that cover the changes made in this PR
    • I added steps for local testing in the Tests section
    • I added steps for Staging and/or Production testing in the QA steps section
    • I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
  • I included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on:
    • iOS / native
    • Android / native
    • iOS / Safari
    • Android / Chrome
    • MacOS / Chrome
    • MacOS / Desktop
  • I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed)
  • I followed proper code patterns (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick)
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text shown in the product was added in all src/languages/* files
    • I verified any copy / text that was added to the app is correct English and approved by marketing by adding the Waiting for Copy label for a copy review on the original GH to get the correct copy.
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I followed the guidelines as stated in the Review Guidelines
  • I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar are working as expected)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.js or at the top of the file that uses the constant) are defined as such
  • If a new component is created I verified that:
    • A similar component doesn't exist in the codebase
    • All props are defined accurately and each prop has a /** comment above it */
    • The file is named correctly
    • The component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone
    • The only data being stored in the state is data necessary for rendering and nothing else
    • For Class Components, any internal methods passed to components event handlers are bound to this properly so there are no scoping issues (i.e. for onClick={this.submit} the method this.submit should be bound to this in the constructor)
    • Any internal methods bound to this are necessary to be bound (i.e. avoid this.submit = this.submit.bind(this); if this.submit is never passed to a component event handler like onClick)
    • All JSX used for rendering exists in the render method
    • The component has the minimum amount of code necessary for its purpose, and it is broken down into smaller components in order to separate concerns and functions
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(themeColors.componentBG)
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • I have checked off every checkbox in the PR author checklist, including those that don't apply to this PR.

PR Reviewer Checklist

The reviewer will copy/paste it into a new comment and complete it after the author checklist is completed

  • I have verified the author checklist is complete (all boxes are checked off).
  • I verified the correct issue is linked in the ### Fixed Issues section above
  • I verified testing steps are clear and they cover the changes made in this PR
    • I verified the steps for local testing are in the Tests section
    • I verified the steps for Staging and/or Production testing are in the QA steps section
    • I verified the steps cover any possible failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
  • I checked that screenshots or videos are included for tests on all platforms
  • I included screenshots or videos for tests on all platforms
  • I verified tests pass on all platforms & I tested again on:
    • iOS / native
    • Android / native
    • iOS / Safari
    • Android / Chrome
    • MacOS / Chrome
    • MacOS / Desktop
  • If there are any errors in the console that are unrelated to this PR, I either fixed them (preferred) or linked to where I reported them in Slack
  • I verified proper code patterns were followed (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick).
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text shown in the product was added in all src/languages/* files
    • I verified any copy / text that was added to the app is correct English and approved by marketing by adding the Waiting for Copy label for a copy review on the original GH to get the correct copy.
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I verified that this PR follows the guidelines as stated in the Review Guidelines
  • I verified other components that can be impacted by these changes have been tested, and I retested again (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar have been tested & I retested again)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.js or at the top of the file that uses the constant) are defined as such
  • If a new component is created I verified that:
    • A similar component doesn't exist in the codebase
    • All props are defined accurately and each prop has a /** comment above it */
    • The file is named correctly
    • The component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone
    • The only data being stored in the state is data necessary for rendering and nothing else
    • For Class Components, any internal methods passed to components event handlers are bound to this properly so there are no scoping issues (i.e. for onClick={this.submit} the method this.submit should be bound to this in the constructor)
    • Any internal methods bound to this are necessary to be bound (i.e. avoid this.submit = this.submit.bind(this); if this.submit is never passed to a component event handler like onClick)
    • All JSX used for rendering exists in the render method
    • The component has the minimum amount of code necessary for its purpose, and it is broken down into smaller components in order to separate concerns and functions
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(themeColors.componentBG)
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • I have checked off every checkbox in the PR reviewer checklist, including those that don't apply to this PR.

Screenshots

Web

Web

OwEUNLz5pt

Mobile Web - Chrome

Mobile Chrome

xSlwcAgUv6

Mobile Web - Safari

Mobile Safari

jvz1j2vpmQ

Desktop

Desktop

jYtndGIw97

iOS

iOS

jQKFKtEXND

Android

@ctkochan22 ctkochan22 requested a review from a team as a code owner October 25, 2022 02:59
@ctkochan22 ctkochan22 self-assigned this Oct 25, 2022
@melvin-bot melvin-bot bot requested review from rushatgabhane and tgolen and removed request for a team October 25, 2022 03:00
@nkuoch
Copy link
Contributor

nkuoch commented Oct 25, 2022

Looking at your videos, I see a weird panel behavior where is starts to close and opens back

@@ -58,6 +59,14 @@ class WorkspaceBankAccountPage extends React.Component {
this.navigateToBankAccountRoute();
}

componentDidUpdate(prevProps) {
Copy link
Contributor

@nkuoch nkuoch Oct 25, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm ....

So, you're doing this because you want to wait for the RestartBankAccountSetup call to finish (which deletes the free plan bank account) before calling navigateToBankAccountRoute (which calls fetchFreePlanVerifiedBankAccount), so it doesn't end up fetching a deleted bank account.

Personally, I would prefer calling API.makeRequestWithSideEffects('RestartBankAccountSetup' than doing this even though I know we want to avoid it.

Or another alternative would be to somehow pass a param to navigateToBankAccountRoute to tell it not to call fetchFreePlanVerifiedBankAccount in this case, as we should just be able to rely on the optimistic data that we put (that resets REIMBURSEMENT_ACCOUNT). Can you try it see if it would work?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like that second option better of passing a route parameter to avoid the fetch. Another alternative to that would be to have two components:

  1. Does the fetch on mounting (this is the one users normally hit in the flow)
  2. Doesn't do the fetch (you can only get to this component by being redirected to it from resetFreePlanBankAccount()

It's sorta the same thing as a route parameter but implemented in a slightly different way.

Copy link
Contributor Author

@ctkochan22 ctkochan22 Oct 25, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thats interesting. I wonder if we can do a bit of both. There are actually two problems here:

  1. User resets VBBA and then we immediately do a fetch
  2. When user logs in for the first time, we don't do any sort of fetch before WorkspaceBankAccountPage, so we skip this step entirely. Which is a bit strange
    image

We could:

  1. Always fetch VBBA upon getting to WorkspaceBankAccountPage component
  2. If we navigate to /bank-account from this component, we always skip fetching (since we just did one)
  3. If user chooses to "Start Over", we call the API. Skip the fetch, so we have no issue.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good to me

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Passing in a param to navigate is trickier than I thought. Still working

@ctkochan22
Copy link
Contributor Author

Closing in favor of this solution: #12422

@rushatgabhane
Copy link
Member

@ctkochan22 this PR should be closed, right?

@ctkochan22
Copy link
Contributor Author

Yes!

@ctkochan22 ctkochan22 closed this Nov 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants